﻿
var Textarea = {
    model: function (d = {}) {
        this.Title = d.Title || "多行文本";
        this.EnTitle = d.EnTitle || "";
        this.Tips = d.Tips || "";
        this.Name = d.Name || 'lg' + lg.GetSN(6, 10);
        this.Value = d.Value || "";
        this.ExportName = d.ExportName || "";
        this.Width = d.Width || "100%";
        this.Required = d.Required || false;
        this.IsRender = d.IsRender != undefined ? d.IsRender : true;
        this.Range = d.Range || [0, 0];
        this.IsShow = d.IsShow || false;
        this.IsExport = d.IsExport || false;
        this.IsWhere = d.IsWhere || false;
        this.WhereKey = d.WhereKey || "精确匹配"
    },
    component: {
		name: "lg-form-textarea",
		data: {
			props: {
				items: {
					type: Array,
					default: []
				},
				value: {
					type: [String, Object],
					default: ""
				},
				data: {
					type: Object,
					default: {}
				},
				renderType: {
					type: Number,
					default: 0
				}
			},
            template: `
            <div :class="['lg-form-item pane',{'lg-ver-error':data.error},{'pointer-none':renderType==1}]" :style="{'width':data.Width}">
			  <div class="lg-form-block">
			    <div class="lg-form-title">
			      <div class="lg-form-title-item">
			        <i v-if="data.Required">*</i>
                    <span class="cn">{{data.Title}}</span>
                    <span class="en">{{data.EnTitle}}</span>
			      </div>
			    </div>
			    <div class="lg-form-control">
			      <textarea rows="4" class="lg-textarea" :value="value" @input="$emit('update:value', $event.target.value)"></textarea>
			    </div>
			  </div>
			  <div class="lg-form-block">
			    <div class="lg-form-tip" v-if="!data.error">{{data.Tips}}</div>
			    <div class="lg-form-ver" v-if="data.error">{{data.errMsg}}</div>
			  </div>
			</div>
			`
		}
    }
}

Textarea.model.prototype.verify = function () {
    var res = { state: true, msg: "ok" };
    if (this.Required) {
        res.state = lg.regx.required(this.Value);
        if (!res.state) {
            res.msg = "必填项不可为空!";
            return res;
        }
    }
    if (this.Value && this.TextLength) {
        var res = { state: true, msg: "ok" };
        if (this.TextLength.indexOf("~") > -1) {
            res.state = lg.regx.textRane(this.Value, this.TextLength.split("~"));
        } else {
            res.state = lg.regx.textRane(this.Value, this.TextLength);
        }
        if (!res.state) {
            res.msg = "字符长度不在允许的范围内！";
        }
    }
    return res
}

export { Textarea }